
package de.fhhof.brst.user;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import de.fhhof.brst.dao.HibernateUserDAO;
import de.fhhof.brst.dao.UserDAO;
import de.fhhof.brst.data.User;
@ManagedBean
@RequestScoped
public class UserManager implements Serializable {
  /**
   * 
   */
  private static final long serialVersionUID =  -7676801093462899464L;

  private List<de.fhhof.brst.data.User> users;

  private de.fhhof.brst.data.User[] selectedUsers;

  private de.fhhof.brst.dao.UserDAO userDAO =  HibernateUserDAO.getHibernateUserDAO();

  public UserManager() {
		users = userDAO.getAllUser();
  }

  public List<de.fhhof.brst.data.User> getUsers() {
		return users;
  }

  public de.fhhof.brst.data.User[] getSelectedUsers() {
		return selectedUsers;
  }

  public void setSelectedUsers(de.fhhof.brst.data.User[] selectedUsers) {
		this.selectedUsers = selectedUsers;
  }

  public String delete() {
		for(User deleteUser : selectedUsers) {
			System.out.println(deleteUser.getEmail());
			userDAO.deleteUser(deleteUser);
		}
		
		return "/users_frame.xhtml?faces-redirect=true";
  }

}
